﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 厚度圆
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Bitmap bitmap;
        void MyClear(Bitmap bitmap)
        {
            for (int i = 0; i < bitmap.Width; ++i)
            {
                for (int j = 0; j < bitmap.Height; ++j)
                {
                    bitmap.SetPixel(i, j, Color.FromArgb(255, 255, 255));
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            bitmap = new Bitmap(500, 500);
            MyClear(bitmap);
            pictureBox1.Image = bitmap;
        }

        void MultiArc(int x,int y,Color color)
        {
            bitmap.SetPixel(x + 250, y + 250, color);
            bitmap.SetPixel(250 + y, 250 - x, color);
            bitmap.SetPixel(250 - x, 250 - y, color);
            bitmap.SetPixel(250 - y, 250 + x, color);

            bitmap.SetPixel(250 + x, 250 - y, color);
            bitmap.SetPixel(250 - x, 250 + y, color);
            bitmap.SetPixel(250 - y, 250 - x, color);
            bitmap.SetPixel(250 + y, 250 + x, color);
        }

        void MidpointCircle(int r,Color color)
        {
            int x = 0;
            int y = r;
            int deltax = 3;
            int deltay = 2 - r - r;
            int d = 1 - r;
            MultiArc(x, y, color);
            while(x<y)
            {
                if(d<0)
                {
                    d += deltax;
                    deltax += 2;
                    x++;
                }
                else
                {
                    d += (deltax + deltay);
                    deltax += 2;
                    deltay += 2;
                    x++;
                    MultiArc(x, y, color);
                    y--;
                }
                MultiArc(x, y, color);

            }
        }
        int stoi(string s)
        {
            int sum = 0;
            for (int i = 0; i < s.Length;++i )
            {
                sum+=sum*10+s[i]-'0';
            }
            return sum;
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            MyClear(bitmap);
            int m = stoi(textBox2.Text);
            int r = stoi(textBox1.Text);
            if(m>=0 && r>=0)
            for (int i = 0; i < m; ++i)
            {
                MidpointCircle(r + i, Color.FromArgb(0, 0, 0));
            }
            
            pictureBox1.Image = bitmap;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }


    }
}
